import reprlib
print(reprlib.repr(set('supercalifragilisticexpialidocious')))

import pprint
t=[[[['black','cyan'],'white',['green','blue']],[['magenta','yellow'],'blue']]]
# pprint.pprint(t,width=30)

import textwrap
doc="""the wrap() method is just like fill() except that it returns
a list of strings instead of one big string with newlines to separate
the wrapped lines.
"""
# print(textwrap.fill(doc,width=40))

import locale
# locale.setlocale(locale.LC_ALL, 'English_United States.1252')
# # print(locale)
# conv=locale.localeconv()
# x = 1234567.8
# locale.format_string("%d", x, grouping=True)
# locale.format_string("%s%.*f",(conv['currency_symbol'],
#                                conv['frac_digits'],x),grouping=True)
from string import Template
# t=Template('${village}folk send $$10 to $cause.')
# t.substitute(village='Nottingham',cause='the ditch fund')
# print(t)

import time,os.path
# photofiles = ['img_1074.jpg','img_1074.jpg','img_1074.jpg','img_1074.jpg']
# class BatchRename(Template):
#     delimiter = '%'
# fmt = input("Enter rename style (%d-date %n-swqnum %f-format): ")
# t = BatchRename(fmt)
# date = time.strftime('%d%b%y')
# for i , filename in enumerate(photofiles):
#     base , ext = os.path.splitext(filename)
#     newname= t.substitute(d=date , n=i , f=ext)
#     print('{0}-->{1}'.format(filename , newname))

import struct
with open('D:\\test\\myfile.zip','rb') as f:
    data = f.read()
start = 0
for i in range(3):
    start +=14
    fields = struct.unpack('<IIIHH' , data[start:start+16])
    crc32,comp_size,uncomp_size , filenamesize , extra_size = fields
    start += 16
    filename = data[start:start+filenamesize]
    start += filenamesize
    extra = data[start: start+extra_size]
    print(filename , hex(crc32) , comp_size , uncomp_size)
    start += extra_size+comp_size

import threading , zipfile
class AsyncZip(threading.Thread):
    def __init__(self , infile , outfile):
        threading.Thread.__init__(self)
        self.infile = infile
        self.outfile= outfile
    def run(self):
        f = zipfile.ZipFile(self.outfile , 'w' , zipfile.ZIP_DEFLATED)
        f.write(self.infile)
        f.close()
        print("Finished background zip of : " , self.infile)
background = AsyncZip('D:\\test\\2.txt','D:\\test\\2.zip')
background.start()
print("the main program continues to run in foreground ")
background.join()
print("main program waited until background was done . ")


import logging
# logging.debug("Debugging information")
# logging.info("informational message")
# logging.warning("warning message")
# logging.error("error message")
# logging.critical("critical message")
print("*******"*10)
import weakref , gc
# class A:
#     def __init__(self , value):
#         self.value = value
#     def __repr__(self):
#         return str(self.value)
# a=A(10)
# d = weakref.WeakValueDictionary()
# d['primary'] = a
# print(d['primary'])
# del a
# gc.collect()
# d['primary']

from array import array
a = array('H' , [4000 , 10 , 700 , 22222])
# print(sum(a))
# print(a[1:3])
# print(sum(a[1:3]))

from collections import deque
d  = deque(["task1" , "task2" , "task3" , "task4" , "task5"])
d.append("task6")
# print("Handling" , d.popleft())

d = deque(["task1" , "task2" , "task3" , "task4" ])
# def breadth_first_search(d):
#     node = d.popleft()
#     for m in gen_moves(node):
#         if is_goal(m):
#             return m
#         d.appendleft(m)

import bisect
scores=[(100,'perl') , (200 , 'tcl') , (400 , 'lua') , (500,'python')]
bisect.insort(scores , (300 , 'ruby'))
print(scores)

from heapq import heapify , heappop , heappush
data = [ 1, 3, 5, 7 , 9 , 2 , 4, 6 , 8 , 0]
heapify(data)
heappush(data , -5)
print([heappop(data) for i in range(11)])
print("===="*20)
from decimal import  *
print(round(Decimal('0.70') * Decimal('1.05') , 3))
print(round(.70*1.05, 2))

print(Decimal('1.00') % Decimal('.10'))
print(1.00 % 0.10)

print(sum([Decimal('0.1')]*10) == Decimal('1.0'))